package cn.mw.cmdb.virtualization.strategy;

import cn.mw.cmdb.virtualization.dto.VirtualizationBaseDto;
import cn.mw.cmdb.virtualization.dto.VirtualizationStorageDto;
import cn.mw.cmdb.virtualization.param.VirtualizationParam;
import cn.mw.cmdb.virtualization.strategy.handler.SyncEngineDataHandler;
import cn.mw.cmdb.virtualization.strategy.handler.VirtualizationTypeHandler;
import cn.mw.microMonitorCommon.entity.common.MwSyncEngineDto;
import cn.mw.microMonitorCommon.enums.SyncEngineTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author gengjb
 * @description 虚拟化类型管理
 * @date 2024/6/26 16:59
 */
@Component
@Slf4j
public class VirtualizationTypeManager {

    Map<String, VirtualizationTypeHandler> handlerMap = new HashMap<>();

    @Autowired
    private ApplicationContext applicationContext;

    @PostConstruct
    public void init(){
        Map<String, VirtualizationTypeHandler> beans = applicationContext.getBeansOfType(VirtualizationTypeHandler.class);
        for (VirtualizationTypeHandler bean : beans.values()) {
            List<String> types = bean.getType();
            if(CollectionUtils.isNotEmpty(types)){
                types.forEach(item->{
                    handlerMap.put(item,bean);
                });
            }
        }
    }

    public Object getTypeData(String type, List<VirtualizationBaseDto> baseDtos,VirtualizationParam param,Integer serverId){
        if(StringUtils.isEmpty(type)){
            return null;
        }
        return handlerMap.get(type).getTypeData(baseDtos,param,serverId);
    }
}
